package me.gujun.ohos.taggroup.entry;

import me.gujun.ohos.taggroup.TagGroup;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;

public class TagEditorAbility extends Ability {
    String[] tags = new String[]{};
    private TagGroup mTagGroup;
    private Component save;
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        if(intent != null){
            tags = intent.getStringArrayParam("tags");
            if(tags == null) {
                tags = new String[]{};
            }
        }
        setUIContent(ResourceTable.Layout_ability_tag_editor);
        mTagGroup = (TagGroup) findComponentById(ResourceTable.Id_tag_group);
        save = findComponentById(ResourceTable.Id_save);
        save.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                Intent data = new Intent();
                data.setParam("tags", mTagGroup.getTags());
                setResult(0x01, data);
                terminateAbility();
            }
        });
        mTagGroup.setTags(tags);
        Intent data = new Intent();
        data.setParam("tags", mTagGroup.getTags());
        setResult(0x01, data);
    }
}
